/**
 * com.cnhis.his.customer.service.Bdo1Service.java
 */
package com.mbmed.doctor.medadvice.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mbmed.doctor.commons.mapper.ModelVo;
import com.mbmed.doctor.medadvice.bo.Acx1Bo;
import com.mbmed.doctor.medadvice.bo.Bdo1Bo;
import com.mbmed.doctor.medadvice.mapper.Acx1;
import com.mbmed.doctor.medadvice.mapper.Bdo1;

/**
 * @file  Bdo1Service.java
 * @author 刘武
 * @version 0.1
 * @todo	Bdo1服务操作接口
 * Copyright(C), 2013-2014
 *		 Shenzhen Coordinates Software Development Co., Ltd.
 * History
 *   	1. Date: 2014-10-28 12:00:27
 *      	Author: 刘武
 *      	Modification: this file was created
 *   	2. ...
 */
@Path("/bdo1")
@Component
public class Bdo1Service {
	
	private static Logger logger = Logger.getLogger(Bdo1.class);
	
	@Autowired
	private Bdo1Bo bdo1Bo;
	@Autowired
	private Acx1Bo acx1Bo;
	
	@Context
	Request request;

	
	/**
	 * 查找所有数据库记录
     * @return type : List 返回查询操作所有符合条件的记录的VO对象集合，操作失败返回null
     */
	@GET
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public List<Bdo1> getAll() throws Exception{
        List<Bdo1> list = new ArrayList<Bdo1>();
        return bdo1Bo.getAll();        
    }
	
    /**
     * 查找符合条件的所有数据库记录
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("{id}")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public Bdo1 getBdo1(@PathParam("id") String id) throws Exception{
    	Bdo1 bdo1 = null;
    	return bdo1Bo.get(id);        
    }
	
	
	
	/**
     * 检索药品分类
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getadivcesearchmedicclass")
	@Produces({MediaType.APPLICATION_JSON})
    public ModelVo getAdivceSearchMedicClass(
    		@QueryParam("bce01") java.lang.String bce01,
    		@QueryParam("bck01") java.lang.String bck01,
    		@QueryParam("beh01") java.lang.String beh01

    		) throws Exception{
		ModelVo modelvo = new ModelVo();
		
		int lbce01 = Integer.parseInt(bce01);
		int lbck01 = Integer.parseInt(bck01);
		
		
		Map<String,Object> paramap = new HashMap<String,Object>();
		List<Bdo1>  list = new ArrayList<Bdo1>();
		
		
		paramap.put("lbce01", lbce01);
		paramap.put("lbck01", lbck01);
		paramap.put("beh01", beh01);

		
		list = bdo1Bo.getAdivceSearchMedicClass(paramap);
		
		
		modelvo.setList(list);
		
    	return modelvo;
	}
	
	
	
	/**
     * 检索药品分类
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getadivcezcymedicclass")
	@Produces({MediaType.APPLICATION_JSON})
    public ModelVo getAdivceZcymedicclass(
    		@QueryParam("bce01") java.lang.String bce01,
    		@QueryParam("bck01") java.lang.String bck01,
    		@QueryParam("beh01") java.lang.String beh01

    		) throws Exception{
		ModelVo modelvo = new ModelVo();
		
		int lbce01 = Integer.parseInt(bce01);
		int lbck01 = Integer.parseInt(bck01);
		
		Map<String,Object> paramap = new HashMap<String,Object>();
		List<Bdo1>  classlist = new ArrayList<Bdo1>();
		
		paramap.put("lbce01", lbce01);
		paramap.put("lbck01", lbck01);
		paramap.put("beh01", beh01);
		classlist = bdo1Bo.getAdivceSearchMedicClass(paramap);
		
		List<Acx1> jzlist = new ArrayList<Acx1>();
		jzlist = acx1Bo.getAll();
		
		Map<String,Object> listmap = new HashMap<String,Object>();
		listmap.put("classlist", classlist);
		listmap.put("jzlist", jzlist);
		
		modelvo.setMap(listmap);
    	return modelvo;
	}
	
	
    /**
     * 向数据库中插入一条记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : 返回插入操作是否成功
     * @throws Exception
     */
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public Bdo1 saveBdo1(
			@FormParam("bdo01") java.lang.Integer bdo01,
			@FormParam("bdo02") java.lang.String bdo02,
			@FormParam("bdo03") java.lang.String bdo03,
			@FormParam("abbrp") java.lang.String abbrp,
			@FormParam("abbrw") java.lang.String abbrw,
			@FormParam("bdo01a") java.lang.Integer bdo01a,
			@FormParam("bdm01") java.lang.String bdm01,
			@FormParam("bdo08") java.util.Date bdo08,
			@FormParam("bdo09") java.util.Date bdo09,
			@Context HttpServletResponse servletResponse
	) throws Exception {
		Bdo1 bdo1 = new Bdo1();
		bdo1.setBdo01(bdo01);
		bdo1.setBdo02(bdo02);
		bdo1.setBdo03(bdo03);
		bdo1.setAbbrp(abbrp);
		bdo1.setAbbrw(abbrw);
		bdo1.setBdo01a(bdo01a);
		bdo1.setBdm01(bdm01);
		bdo1.setBdo08(bdo08);
		bdo1.setBdo09(bdo09);

		return bdo1 = bdo1Bo.save(bdo1);

	}
	/**
     * 删除数据库中与传入的值对象对应的记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : boolean 返回删除操作是否成功
     * @throws Exception
     */
	@DELETE
	@Path("{id}")
	public boolean removeBdo1(@PathParam("id") String id) throws Exception{
		if(id == null) return false;
    	return bdo1Bo.remove(id);

	}
	
}
